-- Poet
-- Created by Zhuangsl Jul/29/2016
-- 吟游诗人

-- 吟游诗人冈布奥的编号
local POET_PET_ID = 7;

-- 初始化
function initPoet(self)
    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local iconPath = getHeroIconPath(POET_PET_ID);

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            local function okFunc1()
                startDialogueTemplate("poet_talk1");
            end

            local function okFunc2()
                startDialogueTemplate("poet_talk2");
            end

            local function okFunc3()
                startDialogueTemplate("poet_talk3");
            end

            local function okFunc4()
                startDialogueTemplate("poet_talk4");
            end

            if not BraveVSDragonM.hasTalkedWithRole(self.gridData.type, 1) then
                -- 发起首次对话
                DungeonActionM.go("talk_with_brave_role", self.gridData:getPos(), 1);

                local function callback()
                    -- 首次对话后，要打开建筑查看界面
                    AudioM.playFx("ui_open1");
                    self:openBuildingView4(okFunc1, okFunc2, okFunc3, okFunc4,
                        getLocStr("peot_button1"), getLocStr("peot_button2"), getLocStr("peot_button3"), getLocStr("peot_button4"),
                        nil, nil, iconPath);
                end

                startDialogueTemplate("poet_first_talk", callback);
                return;
            end

            -- 打开建筑查看界面
            AudioM.playFx("ui_open1");
            self:openBuildingView4(okFunc1, okFunc2, okFunc3, okFunc4,
                getLocStr("peot_button1"), getLocStr("peot_button2"), getLocStr("peot_button3"), getLocStr("peot_button4"),
                nil, nil, iconPath);
        end
    end

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.icon:setScale(1.2);
    self.item:addChild(self.icon);
    self.item:setPositionY(-10);

    -- 呼吸
    self.needAnimation = true;
end
